<template>
  <div>
    <input placeholder="输入关键字搜索" @input="change" />
    <TableVue :list="records" :isShow.sync="isShow" @more="moreFn"></TableVue>
    <MoreVue :isShow.sync="isShow" :moreObject="moreObject"></MoreVue>
  </div>
</template>

<script>
import TableVue from './components/TableVue'
import MoreVue from './components/MoreVue.vue'
export default {
  methods: {
    change(e) {
      if (!e.target.value) return (this.records = this.recordsData)
      this.recordsData.forEach(element => {
        for (let k in element) {
          if (element[k] === e.target.value) {
            return (this.records = [element])
          }
        }
      })
    },
    moreFn(index) {
      this.moreObject = this.records[index]
    }
  },
  components: {
    TableVue,
    MoreVue
  },
  data() {
    return {
      isShow: false,
      moreObject: {},
      recordsData: [
        {
          date: '2022-01-01',
          doctor: '张三',
          diagnosis: '感冒',
          prescription: '感冒药'
        },
        {
          date: '2022-02-01',
          doctor: '李四',
          diagnosis: '头疼',
          prescription: '止疼药'
        },
        {
          date: '2022-03-01',
          doctor: '王五',
          diagnosis: '腰痛',
          prescription: '止痛贴'
        }
      ],
      records: [
        {
          date: '2022-01-01',
          doctor: '张三',
          diagnosis: '感冒',
          prescription: '感冒药'
        },
        {
          date: '2022-02-01',
          doctor: '李四',
          diagnosis: '头疼',
          prescription: '止疼药'
        },
        {
          date: '2022-03-01',
          doctor: '王五',
          diagnosis: '腰痛',
          prescription: '止痛贴'
        }
      ]
    }
  }
}
</script>

<style></style>
